package edu.ucsur.libreria.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.ucsur.ventasweb.BusinessLogic.*;

/**
 * Servlet implementation class LoginServlet
 */

public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		  String sUsuario = request.getParameter("txtUsuario");
		  String sPassword = request.getParameter("txtClave");

		  try {
	      LNUsuario oLNUsuario = new LNUsuario();
	      boolean bExiste = oLNUsuario.fbool_ExisteUsuario(sUsuario, sPassword);
	  	  if (bExiste) 
	  	  {
	  		  
	  	    RequestDispatcher dispatcher = request.getRequestDispatcher("/Servicios.jsp");
	  	    dispatcher.forward(request, response);
	  	    
	  	  } 
	  	  else 
	  	  {
	  	    request.setAttribute("msgError", "El valor del usuario y clave no son correctos.");

	  	    RequestDispatcher dispatcher = request.getRequestDispatcher("/Login.jsp");
	  	    dispatcher.forward(request, response);
	  	  }
		  } catch (Exception ex) {
		    ex.printStackTrace();
		  }
		}

}
